#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
const int N=3e3+10,M=2e5+10;
mt19937 rnd(time(0));
char ch[N][N];
int n,m;
int u[N][N],d[N][N],l[N][N],r[N][N];
int a1[N][N],a2[N][N];
int ans;
int s[N];
void solve(int x1,int y1,int x2,int y2)
{
	if(x1==x2||y1==y2)return;
	int lenx=x2-x1+1,leny=y2-y1+1;
//	cerr << "Solve " << x1 << " " << y1 << " " << x2 << " " << y2 << " "<< ans << endl;
//	if(1)
	if(lenx>leny)
	{
		int mid=(x1+x2)/2;
		
		for ( int i = y1 ; i <= y2 ; i++ )
			for ( int j = y1 ; j <= y2 ; j++ )
				a1[i][j]=a2[i][j]=0;
		
		for ( int i = y1 ; i <= y2 ; i++ )
		{
			for ( int j = 0 ; j <= leny ; j++ )s[j]=0;
			for ( int j = mid ; j >= max(u[mid][i],x1) ; j-- )
				s[min(r[j][i]-i,leny)]++;
			for ( int j = leny-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i+1 ; j <= y2 ; j++ )
			{
				if(u[mid][j]>u[mid][i])continue;
				a1[i][j]=s[j-i];
			}
			
			for ( int j = 0 ; j <= leny ; j++ )s[j]=0;
			for ( int j = mid ; j >= max(u[mid][i],x1) ; j-- )
				s[min(i-l[j][i],leny)]++;
			for ( int j = leny-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i-1 ; j >= y1 ; j-- )
			{
				if(u[mid][j]>=u[mid][i])continue;
				a1[j][i]+=s[i-j];
			}
			
			
			for ( int j = 0 ; j <= leny ; j++ )s[j]=0;
			for ( int j = mid+1 ; j <= min(x2,d[mid+1][i]) ; j++ )
				s[min(r[j][i]-i,leny)]++;
			for ( int j = leny-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i+1 ; j <= y2 ; j++ )
			{
				if(d[mid+1][j]<d[mid+1][i])continue;
				a2[i][j]=s[j-i];
			}
			
			for ( int j = 0 ; j <= leny ; j++ )s[j]=0;
			for ( int j = mid+1 ; j <= min(x2,d[mid+1][i]) ; j++ )
				s[min(i-l[j][i],leny)]++;
			for ( int j = leny-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i-1 ; j >= y1 ; j-- )
			{
				if(d[mid+1][j]<=d[mid+1][i])continue;
				a2[j][i]+=s[i-j];
			}
			
			
		}
		
		for ( int i = y1 ; i <= y2 ; i++ )
			for ( int j = i+1 ; j <= y2 ; j++ )
				if(ch[mid][i]==ch[mid+1][i]&&ch[mid][j]==ch[mid+1][j])
				ans+=a1[i][j]*a2[i][j];
				
		solve(x1,y1,mid,y2);
		solve(mid+1,y1,x2,y2);
		
	}else{
	
		int mid=(y1+y2)/2;
		
		for ( int i = x1 ; i <= x2 ; i++ )
			for ( int j = x1 ; j <= x2 ; j++ )
				a1[i][j]=a2[i][j]=0;
		
		for ( int i = x1 ; i <= x2 ; i++ )
		{
//			cerr <<i  <<endl;
			for ( int j = 0 ; j <= lenx ; j++ )s[j]=0;
			for ( int j = mid ; j >= max(l[i][mid],y1) ; j-- )
				s[min(d[i][j]-i,lenx)]++;
			for ( int j = lenx-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i+1 ; j <= x2 ; j++ )
			{
				if(l[j][mid]>l[i][mid])continue;
				a1[i][j]=s[j-i];
			}
			
			for ( int j = 0 ; j <= lenx ; j++ )s[j]=0;
			for ( int j = mid ; j >= max(l[i][mid],y1) ; j-- )
				s[min(i-u[i][j],lenx)]++;
			for ( int j = lenx-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i-1 ; j >= x1 ; j-- )
			{
				if(l[j][mid]>=l[i][mid])continue;
				a1[j][i]+=s[i-j];
			}
//			cerr << "de\n";
			
			
			for ( int j = 0 ; j <= lenx ; j++ )s[j]=0;
			for ( int j = mid+1 ; j <= min(r[i][mid+1],y2) ; j++ )
				s[min(d[i][j]-i,lenx)]++;
			for ( int j = lenx-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
			for ( int j = i+1 ; j <= x2 ; j++ )
			{
				if(r[j][mid+1]<r[i][mid+1])continue;
				a2[i][j]=s[j-i];
			}
			
			for ( int j = 0 ; j <= lenx ; j++ )s[j]=0;
			for ( int j = mid+1 ; j <= min(r[i][mid+1],y2) ; j++ )
				s[min(i-u[i][j],lenx)]++;
			for ( int j = lenx-1 ; j >= 0 ; j-- )s[j]+=s[j+1];
//			for ( int j = 0 ; j <= lenx ; j++ )cerr << s[j] << " ";
//			cerr << endl;
			for ( int j = i-1 ; j >= x1 ; j-- )
			{
				if(r[j][mid+1]<=r[i][mid+1])continue;
				a2[j][i]+=s[i-j];
			}
			
		}
		
//		cerr << "d\n";
		
		for ( int i = x1 ; i <= x2 ; i++ )
			for ( int j = i+1 ; j <= x2 ; j++ )
				if(ch[i][mid]==ch[i][mid+1]&&ch[j][mid]==ch[j][mid+1])
				ans+=a1[i][j]*a2[i][j];
				
		solve(x1,y1,x2,mid);
		solve(x1,mid+1,x2,y2);
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	cin >> n >> m;
	for ( int i = 1 ; i <= n ; i++ )
		for ( int j = 1 ; j <= m ; j++ )
			cin >> ch[i][j];
	for ( int i = 1 ; i <= n ; i++ )
		for ( int j = 1 ; j <= m ; j++ )
		{
			if(ch[i][j]!=ch[i-1][j])u[i][j]=i;
			else u[i][j]=u[i-1][j];
			if(ch[i][j]!=ch[i][j-1])l[i][j]=j;
			else l[i][j]=l[i][j-1];
		}
	for ( int i = n ; i >= 1 ; i-- )
		for ( int j = m ; j >= 1 ; j-- )
		{
			if(ch[i][j]!=ch[i+1][j])d[i][j]=i;
			else d[i][j]=d[i+1][j];
			if(ch[i][j]!=ch[i][j+1])r[i][j]=j;
			else r[i][j]=r[i][j+1];
		}
		
//	for ( int i = 1 ; i <= n ; i++ )
//	{
//		for ( int j = 1 ; j <= m ; j++ )
//			cerr << l[i][j] <<" ";
//		cerr << endl;
//	}
		
//	solve(1,1,2,4);
	solve(1,1,n,m);
	cout << ans;
	return 0;
}


